<template>
  <div class="app-container">
    <!-- 报销 -->
    <el-form
      :model="queryParams"
      ref="queryParams"
      :inline="true"
      v-show="true"
      label-width="68px"
    >
      <el-form-item label="申请人姓名" prop="applyName" class="apply-name">
        <el-input
          v-model="queryParams.applyName"
          placeholder="请输入申请人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提交时间" prop="dateRange" class="time-range">
        <el-date-picker
          v-model="dateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >查询</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="4">
        <div class="table-title">已审批列表</div>
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      :data="dispatchList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="55" align="center"/> -->
      <el-table-column label="申请人姓名" align="center" prop="applyName" />
      <el-table-column label="申请人员工编号" align="center" prop="applyCode" />
      <el-table-column label="流程名称" align="center" prop="processName" />
      <el-table-column label="部门" align="center" prop="deptName" />
      <el-table-column label="详细说明" align="center" prop="detailInfo"  width="250" />
      <el-table-column label="提交时间" align="center" prop="createTime" />
      <el-table-column fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="clickToDetail(scope.$index)"
            type="text"
            size="small"
          >
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { doneList } from "@/api/done/done";

export default {
  name: "",
  props: [""],
  data() {
    return {
      dateRange: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        applyName: null,
        startDate: null,
        endDate: null,
      },
      dispatchList: [],
      total: true,
    };
  },

  components: {},

  computed: {},

  created() {
    this.getList();
  },


  beforeMount() {},

  mounted() {},

  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.startDate = null;
      this.queryParams.endDate = null;
      this.dateRange = null;
      this.handleQuery()
    },
    // 去详情页
    clickToDetail(index) {
      this.$router.push({path:"/doneDetail",
        query:{rId:this.dispatchList[index].rId}
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    getList() {
      this.loading = true;
      doneList(this.queryParams).then((response) => {
        this.dispatchList = response.rows;
        this.dispatchList.forEach((e) => {
          var dateArr = e.createTime.split(" ");
          e.createTime = dateArr[0];
        });
        this.total = response.total;
        this.loading = false;
      });
    },
    foramtDate(dateData) {
      let date = new Date(dateData);
      let y = date.getFullYear();
      let m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      let d = date.getDate();
      d = d < 10 ? "0" + d : d;
      const time = y + "-" + m + "-" + d;
      return time;
    },
    clickBatchThrough(){
      this.batchThroughVisible= true;
    },
    clickNotBatchThrough(){
      this.batchNotThroughVisible= true;
    }
  },

  watch: {
    dateRange: function (newVal, oldVal) { 
      this.queryParams.startDate = this.foramtDate(newVal[0]);
      this.queryParams.endDate = this.foramtDate(newVal[1]);
    },
  },
};
</script>

<style lang="scss">
.apply-name {
  .el-form-item__label {
    width: 82px !important;
  }
}

.time-range {
  margin-left: 15px;
}

.table-title {
  font-size: 14px;
  color: #606266;
  margin-bottom: 10px;
  font-weight: 700;
}
</style>